home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 7 / FM Towns Free Software Collection 7.iso / taropyon / cci / find.cci < prev    next >
Text File  |  1993-11-30  |  1KB  |  78 lines

  1. /*************************************************************************
  2. *    "find.cci" : パターン検索(コンソール用)
  3. *-------------------------------------------------------------------------
  4. *    使い方:
  5. *        CCI find -- <検索パターン> <ファイル名>
  6. *************************************************************************/
  7.  
  8. #include    "ccilib.h"
  9.  
  10. int            FlgI = 0;
  11. char        *Ptn = NULL;
  12. char        *RePtn = NULL;
  13.  
  14. int        find( char *fn )
  15. {
  16.     char    *fp;
  17.     char    buf[BUFSIZ];
  18.     long    ln;                /* 行番号    */
  19.  
  20.     if ( (fp = fopen(fn,"r")) == NULL )
  21.     {
  22.         fprintf(stderr,"File open error!! (%s)\n", fn );
  23.         return (ERR);
  24.     }
  25.  
  26.     ln = 0;
  27.     while ( fgets(buf,BUFSIZ,fp) != NULL )
  28.     {
  29.         ++ln;
  30.         if ( RePtnMatch( RePtn, buf ) >= 0 )
  31.         {    /* マッチング */
  32.             printf("%6d : %s", ln, buf );
  33.         }
  34.     }
  35.  
  36.     fclose(fp);
  37.     return (NORMAL);
  38. }
  39.  
  40. int        main( int argc, char **argv)
  41. {
  42.     int        i, ch;
  43.     char    *s;
  44.  
  45.     for ( i = 1; i < argc; ++i )
  46.     {
  47.         s = argv[i];
  48.         if ( *s == '-' || *s == '/' )
  49.         {    /* オプションパラメータ */
  50.             ++s;
  51.             while ( *s )
  52.             {
  53.                 ch = toupper(*s++);
  54.                 switch ( ch )
  55.                 {
  56.                     case 'I':
  57.                         FlgI = 1;
  58.                         break;
  59.                 }
  60.             }
  61.         } else
  62.         {
  63.             if ( Ptn == NULL )
  64.             {    /* 検索パターン    */
  65.                 Ptn = s;
  66.                 /* 検索パターンのコンパイル    */
  67.                 if ( (RePtn = RePtnAlloc( Ptn, FlgI )) == NULL )
  68.                 {
  69.                     fprintf(stderr,"Pattern error!!\n");
  70.                     exit(1);
  71.                 }
  72.             } else
  73.                 find( s );
  74.         }
  75.     }
  76.     return (0);
  77. }
  78.